#!/bin/bash
set -o nounset
set -o errexit
#set -o xtrace

function usage() {
    cat <<EOF
Usage: start-aio <version>      to start an all-in-one k8s cluster with a specific kubeasz version

EOF
}

[[ "$#" -eq 1 ]] || { usage >&2; exit 1; }

# 
rm -f easzup

# tool
echo "[INFO] get the tool script: easzup"
if [[ -e /usr/bin/curl ]];then
  curl -C- -fLO --retry 3 "https://github.com/easzlab/kubeasz/releases/download/$1/easzup" || exit 1
else
  wget -c "https://github.com/easzlab/kubeasz/releases/download/$1/easzup" || exit 1
fi

# download
echo "[INFO] download everything with easzup"
chmod +x ./easzup
./easzup -D
#./easzup -P

# install
echo "[INFO] install k8s using a container 'kubeasz'"
./easzup -S
docker exec -it kubeasz easzctl start-aio
